#include <iostream>
#include "test.h"
using namespace std;

class yzw
{
public:
	friend istream& operator>>(istream& in, yzw &s);

	void yzw_input(int n,size_t t)
	{
		if (_size = _capacity)
		{
			int* tmp = (int*)realloc(arr, _capacity * 2);
			memcpy(tmp, arr, _capacity * 4);
			delete[] arr;
			arr = tmp;
		}
		this->arr[t] = n;
		this->_size++;
	}

	yzw operator+(yzw& s)
	{
		yzw s1;
		int min = s.size();
		if (this->size() < min)
		{
			min = this->size();
		}

		for (int i = 0; i < min; i++)
		{
			s1.yzw_input(this->arr[i] + s.arr[i], i);
		}
		int max = s.size();
		int flge = 0;
		if (this->size() > max)
		{
			max = this->size();
			flge = 1;
		}
		for (int i = min; i < max; i++)
		{
			if(flge = 1)
			s1.yzw_input(this->arr[i], i);
			else
			s1.yzw_input(s.arr[i], i);
		}
		return s1;
	}

	void print()
	{
		for (int i = 0; i < size(); i++)
		{
			cout << i << ' ' << arr[i] << ' ';
		}
	}

	yzw(size_t n = 2)
	{
		arr = new int[n] {0};
		_size = 0;
		_capacity = n;
	}

	size_t size()
	{
		return _size;
	}

	int& operator[](size_t n)
	{
		return arr[n];
	}
private:
	int* arr;
	size_t _size;
	size_t _capacity;
};

istream& operator>>(istream& cin,yzw& s1)
{
		size_t t;
		int n;
		cin >> t;
		cin >> n;
		s1.yzw_input(n,t);
	return cin;
}

void test()
{
	yzw s1;
	cin >> s1;
	//s1.yzw_input(1, 0);
	//s1.arr[0] = 1;
	s1.print();
}

void test01()
{
	yzw s1;
	//yzw s2;
	//yzw s3;
	s1.yzw_input(0, 1);
	//s2.yzw_input(0, 2);

	s1.print();
	//s2.print();

	//s3 = s1 + s2;
	//s3.print();
}




int main()
{
	///test();
	test012();
	//test02();
	
	return 0;
}